﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace AppServer.Controllers.System
{
    [Route("api/[controller]")]
    [ApiController]
    public class System7Controller : SysControllerBase
    {
        //菜单
        // POST: api/System7
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action==null?"Get": data.Action;
            string rtstr = "";
            //得到列表
            if (Action == "Get")
            {
                rtstr = GetByUser(data);
            }
            //得到列表
            if (Action == "GetList")
            {
                rtstr = GetList(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到菜单列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string GetByUser(dynamic data)
        {
            BLLsystem_7 bll = new BLLsystem_7();
            List<Mssystem_7> mssys7 = new List<Mssystem_7>();
            Mssystem_1 lodeuser = GetSessionUser();
            mssys7 = bll.GetHeadMenuByUser(lodeuser);


            return JArray.FromObject(mssys7).ToString();
        }
        /// <summary>
        /// 得到菜单列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string GetList(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            string search = postdata["search"].ToString();
            BLLsystem_7 bll = new BLLsystem_7();
            List<Mssystem_7> mssys7 = new List<Mssystem_7>();
            MsQuery ms = new MsQuery();
            //条件
            if (!string.IsNullOrEmpty(search))
            {
                ms.strquery += " and (SYSTEM_7_20 like '%" + search + "%' )";
            }
            //ms.strorder = "  ";//排序语句
            mssys7 = new BLLsystem_7().Getsystem_7MsByQuery(ms);

            return JArray.FromObject(mssys7).ToString();
        }
    }
}
